package com.maimao.search.client.factory;

import com.maimao.core.enums.RespCode;
import com.maimao.core.model.resp.Result;
import com.maimao.model.goods.Category;
import com.maimao.model.goods.vo.GoodsInfo;
import com.maimao.search.client.CateClient;
import com.maimao.search.client.GoodsClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class CateFallBackFactory implements FallbackFactory<CateClient> {

    @Override
    public CateClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new CateClient() {
            @Override
            public Result<List<String>> selectNamesByIds(List<Integer> ids) {
                log.error("调用[CateClient-selectNamesByIds({})]出错 :{}", ids, errorMsg);
                return Result.fail(RespCode.FAIL);
            }

            @Override
            public Result<List<Category>> selectByIds(List<Integer> ids) {
                log.error("调用[CateClient-selectByIds({})]出错 :{}", ids, errorMsg);
                return Result.fail(RespCode.FAIL);            }


        };
    }
}
